<template>
  <div>
    <el-dialog :title="this.ruleForm.id ? '修改' : '新增'" :visible="showDialog" width="30%" :before-close="handleClose" :close-on-click-modal="false">
      <div class="content">
        <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="120px" class="demo-ruleForm">
            <el-form-item label="作物种类" prop="cropType" class="show_start" >
                <el-select  v-model="ruleForm.cropType" filterable placeholder="请选择作物种类或输入关键词">
                    <el-option v-for="item in cropTypeList" :key="item.label" :label="item.label" :value="item.label">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="合同量(万斤)" prop="contractNumber" class="show_start">
              <el-input v-model="ruleForm.contractNumber" placeholder="请输入合同量"></el-input>
            </el-form-item>
        </el-form>
      </div>
      <div class="dialog-footer">
        <el-button class="submit" @click="handleSubmit">确 认</el-button>
        <el-button class="back" @click="handleClose">返 回</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import rules from '@/utils/rules'
import { getCropTypeApi } from '@/api/inCage'
export default {
  props: ['showDialog','addTableDate'],
  data() {
    return {
      ruleForm: {
        cropType: '',
        contractNumber: '',
      },
      cropTypeList:[],
      rules:rules
    };
  },
  methods: {
    handleClose() {
      this.$emit('update:showDialog', false)
      this.ruleForm = {
        cropType: '',
        contractNumber: '',
      },
        this.$refs.ruleForm.resetFields();
    },
    async handleGetSelect(obj) {
      getCropTypeApi(obj).then((res)=>{
          if(res.code==0){
            this.cropTypeList = res.data
          }
        })
    },
    handleSubmit() {
      this.$refs.ruleForm.validate(async (valid) => {
        if (valid) {
          if (this.ruleForm.id) {
            this.addTableDate("edit",this.ruleForm)
          } else {
            this.addTableDate("add",this.ruleForm)
          }
          this.$emit('handleRefresh')
          this.handleClose()
        } else {
          return false;
        }
      });
    },
  }
}
</script>

<style lang='scss' scoped></style>
